package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.model.Department_lxy;
import com.esm.model.User;
import com.esm.service.AddDepartmentService_lxy;
import com.esm.serviceimpl.AddDepSerImpl_lxy;

import net.sf.json.JSONObject;

/**
 * 这是一个增加部门的controller类
 * @author LiuXingYu
 *
 */
public class AddDepartmentController_lxy extends HttpServlet{
	AddDepartmentService_lxy service=new AddDepSerImpl_lxy();
        @Override
		protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			// TODO Auto-generated method stub
        	doPost(req, resp);
		}
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub resp.setCharacterEncoding("utf8");
      	  PrintWriter pw=resp.getWriter();
      	  HttpSession session=req.getSession();
      	  JSONObject j =new JSONObject();
      	  resp.setCharacterEncoding("utf8");
      	  String deptName=req.getParameter("deptName");
      	  String manager=req.getParameter("manager");
      	  String currentUser=((User)session.getAttribute("currentUser")).getUname();
      	  j.put("value", service.addDepartment(deptName,manager,currentUser));
      	  pw.write(j.toString());
      	  pw.flush();
      	  pw.close();
       
        }
}
